package com.hbnu.array;

import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字小游戏
 *
 * @author chendikai
 * @date 2024-09-10 15:39
 */
public class ArrayDemo05 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        Random random = new Random();
        int number = random.nextInt(100) + 1;

        int guessNumber = 0;

        while (true) {
            System.out.println("请输入1-100之间的整数");
            try {
                guessNumber = Integer.parseInt(scanner.next());
            } catch (NumberFormatException e) {
                System.out.println("你是SB吧....");
                continue;
            }

            if (guessNumber > number) {
                System.out.println("你猜的数字过大......");
            } else if (guessNumber < number) {
                System.out.println("你猜的数字小了......");
            } else {
                System.out.println("恭喜你猜对了！");
                break;
            }

        }
    }
}
